import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import { Tinymce } from '/@/components/Tinymce/index';
export const columns: BasicColumn[] = [
	{
		title: '新闻名称',
		dataIndex: 'title',
		width: 200
	},
	{
		title: '创建时间',
		dataIndex: 'createTime',
		width: 180
	},
	{
		title: '状态',
		dataIndex: 'enabled',
		width: 120,
		customRender: ({ record }) => {
			const enabled = record.enabled;
			const enable = enabled == '0';
			const color = enable ? 'green' : 'red';
			const text = enable ? '正常' : '停用';
			return h(Tag, { color: color }, () => text);
		}
	},
	{
		title: '备注',
		dataIndex: 'remark'
	}
];

export const searchFormSchema: FormSchema[] = [
	{
		field: 'F_title_like',
		label: '新闻名称',
		component: 'Input',
		componentProps: {
			placeholder: '请输入新闻名称'
		},
		colProps: { span: 6 }
	}
];

export const formSchema: FormSchema[] = [
	{
		field: 'id',
		label: 'ID',
		component: 'Input',
		show: false
	},
	{
		field: 'title',
		label: '新闻名称',
		required: true,
		component: 'Input'
	},
	{
		field: 'subTitle',
		label: '副标题',
		component: 'Input'
	},
	{
		field: 'enabled',
		label: '状态',
		component: 'RadioButtonGroup',
		defaultValue: 0,
		componentProps: {
			options: [{ label: '启用', value: 0 }, { label: '停用', value: 1 }]
		}
	},
	{
		field: 'content',
		label: '新闻内容',
		required: true,
		component: 'Input',
		render: ({ model, field }) => {
			return h(Tinymce, {
				value: model[field],
				onChange: (value: string) => {
					model[field] = value;
				}
			});
		}
	},
	{
		label: '备注',
		field: 'remark',
		component: 'InputTextArea'
	}
];
